//
//  CYBillCell.m
//  cyjf
//
//  Created by tauCross on 2017/8/30.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYBillCell.h"



@implementation CYBillCellObject

@end



@interface CYBillCell ()

@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UILabel *dateLabel;
@property(nonatomic, strong)UILabel *amountLabel;
@property(nonatomic, strong)UILabel *balanceLabel;
@property(nonatomic, strong)UIView *bottomLine;

@end


@implementation CYBillCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textColor = HEXCOLOR(@"444444");
        self.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
        [self.contentView addSubview:self.titleLabel];
        
        self.dateLabel = [[UILabel alloc] init];
        self.dateLabel.textColor = HEXCOLOR(@"999999");
        self.dateLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
        [self.contentView addSubview:self.dateLabel];
        
        self.amountLabel = [[UILabel alloc] init];
        self.amountLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
        [self.contentView addSubview:self.amountLabel];
        
        self.balanceLabel = [[UILabel alloc] init];
        self.balanceLabel.textColor = HEXCOLOR(@"999999");
        self.balanceLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
        [self.contentView addSubview:self.balanceLabel];
        
        self.bottomLine = [UIImageView cy_imageLineWithColor:HEXCOLOR(@"ECECEC")];
        [self.contentView addSubview:self.bottomLine];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 65;
}

- (BOOL)shouldUpdateCellWithObject:(CYBillCellObject *)object
{
    self.titleLabel.text = SAFE_STRING(object.model.title);
    
    self.dateLabel.text = SAFE_STRING(object.model.addTimeStr);
    
    self.amountLabel.textColor = SAFE_NUMBER(object.model.value).doubleValue > 0 ? APP_DEFAULT_COLOR_BLUE : HEXCOLOR(@"444444");
    self.amountLabel.text = [NSString stringWithFormat:@"%@%@", SAFE_NUMBER(object.model.value).doubleValue >= 0 ? @"+" : @"", SAFE_NUMBER(object.model.value).amountString];
    
    self.balanceLabel.text = [NSString stringWithFormat:@"余额:%@", SAFE_NUMBER(object.model.walletTotle).amountString];
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.titleLabel sizeToFit];
    self.titleLabel.left = 20;
    self.titleLabel.centerY = 20;
    
    [self.dateLabel sizeToFit];
    self.dateLabel.left = 20;
    self.dateLabel.centerY = 42.5;
    
    [self.amountLabel sizeToFit];
    self.amountLabel.right = self.contentView.width - 20;
    self.amountLabel.centerY = 24;
    
    [self.balanceLabel sizeToFit];
    self.balanceLabel.right = self.contentView.width - 20;
    self.balanceLabel.centerY = 44;
    
    self.bottomLine.width = self.contentView.width - 20;
    self.bottomLine.height = 1 / SCREEN_SCALE;
    self.bottomLine.bottom = self.contentView.height;
    self.bottomLine.right = self.contentView.width;
}

@end
